import { IsNumber, IsOptional, IsString, Max } from 'class-validator';
import { Transform } from 'class-transformer';

class PaginationDto {
  @IsNumber({
    maxDecimalPlaces: 0,
  })
  @IsOptional()
  @Transform(({ value }) => (value ? Number(value) : 0))
  skip: number;

  @IsNumber({
    maxDecimalPlaces: 0,
  })
  @IsOptional()
  @Max(100, { message: '单次查询数量超过限制!' })
  @Transform(({ value }) => (value ? Number(value) : 10))
  take: number;
}

export class SearchResultDto {
  data: {
    hash: string;

    title: string;

    size: string;

    category: string;

    create_time: number | undefined;

    added_time: number;
  }[];

  total: number;
}

export class SearchRequestDto extends PaginationDto {
  @IsOptional()
  @IsString()
  query?: string;
}
